/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eyrolles;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletContext;
import org.apache.struts.action.Action;

/**
 *
 * @author julientrebern
 */
public class ActionDB extends Action {

    protected Connection conn = null;
    protected Statement stmt = null;
    protected ResultSet rs = null;

    protected Connection getConnection() {
        ServletContext context = servlet.getServletContext();
        DBConnectionManager DBManager = (DBConnectionManager) context.getAttribute("DBManager");
        return (DBManager.getConnection("cotations"));
    }

    protected void freeConnection(Connection conn) {
        ServletContext context = servlet.getServletContext();
        DBConnectionManager DBManager = (DBConnectionManager) context.getAttribute("DBManager");
        DBManager.freeConnection("cotations", conn);
    }

    protected void closeConnection() throws SQLException {

        if (rs != null) {

            rs.close();
            rs = null;
        }
        if (stmt != null) {

            stmt.close();
            stmt = null;
        }
        if (conn != null) {

            freeConnection(conn);
            conn = null;
        }
    }
}
